/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package racesuitefx.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Wolfgang
 */
@Entity
@Table(name = "lap")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Lap.findAll", query = "SELECT l FROM Lap l"),
    @NamedQuery(name = "Lap.findByRaceId", query = "SELECT l FROM Lap l WHERE l.lapPK.raceId = :raceId"),
    @NamedQuery(name = "Lap.findByTagId", query = "SELECT l FROM Lap l WHERE l.lapPK.tagId = :tagId"),
    @NamedQuery(name = "Lap.findByTime", query = "SELECT l FROM Lap l WHERE l.lapPK.time = :time")})
public class Lap implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected LapPK lapPK;
    @JoinColumn(name = "raceId", referencedColumnName = "raceId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Race race;
    @JoinColumn(name = "tagId", referencedColumnName = "tagId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Tag tag;

    public Lap() {
    }

    public Lap(LapPK lapPK) {
        this.lapPK = lapPK;
    }

    public Lap(int raceId, String tagId, Date time) {
        this.lapPK = new LapPK(raceId, tagId, time);
    }

    public LapPK getLapPK() {
        return lapPK;
    }

    public void setLapPK(LapPK lapPK) {
        this.lapPK = lapPK;
    }

    public Race getRace() {
        return race;
    }

    public void setRace(Race race) {
        this.race = race;
    }

    public Tag getTag() {
        return tag;
    }

    public void setTag(Tag tag) {
        this.tag = tag;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (lapPK != null ? lapPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Lap)) {
            return false;
        }
        Lap other = (Lap) object;
        if ((this.lapPK == null && other.lapPK != null) || (this.lapPK != null && !this.lapPK.equals(other.lapPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "racesuitefx.entities.Lap[ lapPK=" + lapPK + " ]";
    }
    
}
